package caip2021p.rcv5;

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();

        // 读取n和m
        String[] lineArr = br.readLine().split(" ");
        int n = Integer.parseInt(lineArr[0]);
        int m = Integer.parseInt(lineArr[1]);

        // 使用HashMap存储向量到字符串的映射
        Map<String, String> map = new HashMap<>();

        // 读取n个向量和对应的字符串
        for (int i = 0; i < n; i++) {
            lineArr = br.readLine().split(" ");
            
            List<Integer> list = new ArrayList<>();
            for (int j = 0; j < m; j++) {
               list.add(Integer.parseInt(lineArr[j]));
            }
            String s = lineArr[m]; // 最后一个元素是字符串
            map.put(Arrays.toString(list.toArray()), s);
        }

        br.readLine();//空白行
        
        // 处理查询
        while (true) {
        	lineArr = br.readLine().split(" ");
            

            // 检查终止条件
            if (lineArr[0].equals("0")) {
                break;
            }

            List<Integer> list = new ArrayList<>();
            for (int i = 0; i < m; i++) {
                list.add(Integer.parseInt(lineArr[i]));
            }
            
            // 查询并输出结果
            String result = map.get(Arrays.toString(list.toArray()));
            if (result == null) {
                sb.append("Pass");
                sb.append("\n");
            } else {
                sb.append(result);
                sb.append("\n");
            }
        }

        System.out.print(sb.toString());
    }
}
